package top.idcard.agent.biz.core;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

/**
 * @author wx
 * @version 1.0
 * @date 2021/2/1 4:10 下午
 */
public class IndexConfig {

    private List<IndexUnit> nativeIndex;
    private List<IndexUnit> hongIndex;
    private List<IndexUnit> foreignIndex;

    public IndexConfig(List<IndexUnit> nativeIndex, List<IndexUnit> hongIndex, List<IndexUnit> foreignIndex) {
        this.nativeIndex = nativeIndex;
        this.hongIndex = hongIndex;
        this.foreignIndex = foreignIndex;
    }

    public void addNative(String date, Integer index){
        this.nativeIndex.add(new IndexUnit(date, index, IndexType.Native));
    }

    public void addHong(String date, Integer index){
        this.hongIndex.add(new IndexUnit(date, index, IndexType.Hong));
    }

    public void addForeign(String date, Integer index){
        this.foreignIndex.add(new IndexUnit(date, index, IndexType.Foreign));
    }

    public List<IndexUnit> getNativeIndex() {
        return nativeIndex;
    }

    public List<IndexUnit> getHongIndex() {
        return hongIndex;
    }

    public List<IndexUnit> getForeignIndex() {
        return foreignIndex;
    }

    class IndexUnit{
        private String date;
        private Integer index;
        private IndexType type;

        public IndexUnit(String date, Integer index, IndexType type) {
            this.date = date;
            this.index = index;
            this.type = type;
        }

        public String getDate() {
            return date;
        }

        public Integer getIndex() {
            return index;
        }

        public IndexType getType() {
            return type;
        }
    }

    enum IndexType{
        Native((short)1, ""),
        Hong((short)2, ""),
        Foreign((short)3, "");

        IndexType(short typeValue, String typeName) {
            this.typeValue = typeValue;
            this.typeName = typeName;
        }

        private Short typeValue;
        private String typeName;

        public IndexType valueOf(Short value){
            Optional<IndexType> optional = Arrays.stream(IndexType.values()).filter(item->item.getTypeValue() == value).findFirst();
            if(optional.isPresent()){
                return optional.get();
            }
            return null;
        }

        public Short getTypeValue() {
            return typeValue;
        }

        public String getTypeName() {
            return typeName;
        }
    }
}
